<template>
  <div @click="$router.push(`/prodetail/${goods.id}`)" :style="{ borderBottom: types == 1 ? '1px solid #f2f1f6' : 'none' }">
    <div class="goodsBox" :class="{ 'types1': types == 1 }">
      <div class="goods-item">
        <div class="left">
          <img v-lazy="goods.cover" alt="" />
        </div>
        <div class="right">
          <p class="tit text-ellipsis-2" :style="{ color: types == 1 ? '#000' : '#89888d' }">
            {{ goods.title }}
          </p>
          <div class="labels">
            <span :style="{ background: types == 1 ? '#f2f1f6' : '#30304f', color: types == 1 ? '#807f84' : '#fff' }" class="oneLabel"
              v-for="item in goods.danceList" :key="item.id">{{ item.name }}</span>
          </div>
          <div class="price">
            <div>
              <span class="new">¥{{ goods.minPrice }}</span>
              <span style="font-weight: 500;font-size: 0.2rem;">起</span>
            </div>
          </div>
          <div style="color: #7c7c97;font-size: .3rem;">
            {{ this.$dayjs(goods.startTime).format('YYYY-MM-DD') }}至
            {{ this.$dayjs(goods.endTime).format('YYYY-MM-DD') }}
          </div>
        </div>
      </div>
      <div class="bottom" :style="{ color: types == 1 ? '#807f84' : '#fff' }">
        <p><i><van-icon style="color: #566aff;" name="location" /></i>{{ goods.address }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { addSkuToCart } from '@/apis/cart'
import { mapMutations } from 'vuex'
import { setCollectList } from '@/utils/stroage'
import showNeedLoginDialog from '@/mixins/login-confirm-dialog'

export default {
  mixins: [showNeedLoginDialog],
  data() {
    return {
      showShare: false,
    }
  },
  props: {
    types: {
      type: Number,
      default: 0
    },
    goods: {
      type: Object,
      default: () => { return {} }
    }
  },
  methods: {
    async handlerAddToCart() {
      if (this.showNeedLoginDialog()) {
        return
      }
      // 这种清空添加商品到购物车都是默认的数量1、默认SKU规格
      await addSkuToCart(this.goods.goods_id, 1, '0')
      await this.$store.dispatch('cart/getCartList')
      this.$toast('在购物车等你哦！')
    },
    handlerShareSKU() {
      this.showShare = true
    },
    onSelect(option) {
      this.$toast(option.name)
      this.showShare = false
    },
    handlerCollectSKU() {
      // 将收藏添加到vuex中记录
      this.addSKUToCollectList(this.goods)
      // 保存到本地
      setCollectList(this.$store.state.collect.collectList)
      this.$toast('收藏成功！')
    },
    ...mapMutations('collect', ['addSKUToCollectList'])
  }
}
</script>

<style lang="less" scoped>
.labels {
  overflow: auto hidden;
  width: 48vw !important;
  font-size: .3rem;
  height: .6rem;
  line-height: .6rem;
  white-space: nowrap;
  &::-webkit-scrollbar {
    display: none;
  }
  .oneLabel {
    background: #30304f;
    border-radius: .3rem;
    padding: .2rem .2rem;
    margin-right: .2rem;
  }
}

.goods-item {
  text-align: start;
  height: 3.4rem;
  margin-bottom: 6px;
  padding: .2rem;
  background-color: transparent;
  display: flex;

  .left {
    width: 127px;

    img {
      display: block;
      width: 95%;
      border-radius: 5px;
      height: 105%;
    }
  }

  .right {
    flex: 1;
    font-size: .28rem;
    line-height: 1.3;
    padding: 0 0 0px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: .9rem;

    .tit {
      font-size: .34rem;
    }

    .count {
      color: #999;
      font-size: 12px;
    }

    .price {
      display: flex;
      justify-content: space-between;
      color: #89a8fc;
      font-size: 0.3rem;
      margin-bottom: rem;

      .new {
        font-weight: 700;
        margin-right: 5px;
      }

      .old {
        text-decoration: line-through;
        font-size: 12px;
      }
    }
  }
}

.goodsBox {
  margin: .2rem;
  background: #252540;
  padding: .1rem;
  border-radius: .1rem;
}

.types1 {
  background: #fff;
}

.bottom {
  margin: .2rem 0;

  i {
    color: #566aff;
    margin-right: .2rem;
  }

  p {
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .3rem;
  }
}
</style>
